namespace DataModels.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class OtherSystemsExtension : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.OtherSystemsDistrictDetails",
                c => new
                    {
                        SystemId = c.Int(nullable: false),
                        InternalDistrictId = c.Int(nullable: false),
                        DistrictCode = c.String(nullable: false, maxLength: 50),
                        DistrictName = c.String(nullable: false, maxLength: 255),
                    })
                .PrimaryKey(t => new { t.SystemId, t.InternalDistrictId })
                .ForeignKey("dbo.District", t => t.InternalDistrictId, cascadeDelete: true)
                .ForeignKey("dbo.OtherSystems", t => t.SystemId, cascadeDelete: true)
                .Index(t => t.SystemId)
                .Index(t => t.InternalDistrictId);
            
            CreateTable(
                "dbo.OtherSystemsRegionDetails",
                c => new
                    {
                        SystemId = c.Int(nullable: false),
                        InternalRegionId = c.Int(nullable: false),
                        RegionCode = c.String(nullable: false, maxLength: 50),
                        RegionName = c.String(nullable: false, maxLength: 255),
                    })
                .PrimaryKey(t => new { t.SystemId, t.InternalRegionId })
                .ForeignKey("dbo.OtherSystems", t => t.SystemId, cascadeDelete: true)
                .ForeignKey("dbo.Region", t => t.InternalRegionId, cascadeDelete: true)
                .Index(t => t.SystemId)
                .Index(t => t.InternalRegionId);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.OtherSystemsRegionDetails", "InternalRegionId", "dbo.Region");
            DropForeignKey("dbo.OtherSystemsRegionDetails", "SystemId", "dbo.OtherSystems");
            DropForeignKey("dbo.OtherSystemsDistrictDetails", "SystemId", "dbo.OtherSystems");
            DropForeignKey("dbo.OtherSystemsDistrictDetails", "InternalDistrictId", "dbo.District");
            DropIndex("dbo.OtherSystemsRegionDetails", new[] { "InternalRegionId" });
            DropIndex("dbo.OtherSystemsRegionDetails", new[] { "SystemId" });
            DropIndex("dbo.OtherSystemsDistrictDetails", new[] { "InternalDistrictId" });
            DropIndex("dbo.OtherSystemsDistrictDetails", new[] { "SystemId" });
            DropTable("dbo.OtherSystemsRegionDetails");
            DropTable("dbo.OtherSystemsDistrictDetails");
        }
    }
}
